﻿namespace NMortgage.UI.Tests.ViewModels
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Moq;

    using NMortgage.UI.Events;
    using NMortgage.UI.Model;
    using NMortgage.UI.ViewModels;

    [TestClass]
    public class InterestParameterListViewModelTest : TestBase<InterestParameterListViewModel>
    {
        #region Methods

        [TestMethod]
        public void Cannot_MoveDown_If_Lowest_One()
        {
            Subject.Handle(new ProfileItemAdded(new InterestParameter(DistributionType.FixedRate)));
            var fixedRate = new InterestParameter(DistributionType.FixedRate);
            Subject.Handle(new ProfileItemAdded(fixedRate));
            var actual = Subject.ItemCollection.CanMoveDown(fixedRate);
            Assert.IsFalse(actual);
        }

        [TestMethod]
        public void Cannot_MoveUp_If_Highest_One()
        {
            var fixedRate = new InterestParameter(DistributionType.FixedRate);
            Subject.Handle(new ProfileItemAdded(fixedRate));
            Subject.Handle(new ProfileItemAdded(new InterestParameter(DistributionType.FixedRate)));
            var actual = Subject.ItemCollection.CanMoveUp(fixedRate);
            Assert.IsFalse(actual);
        }

        [TestMethod]
        public void Can_MoveDown_If_Not_Lowest_One()
        {
            var fixedRate = new InterestParameter(DistributionType.FixedRate);
            Subject.Handle(new ProfileItemAdded(fixedRate));
            Subject.Handle(new ProfileItemAdded(new InterestParameter(DistributionType.FixedRate)));
            var actual = Subject.ItemCollection.CanMoveDown(fixedRate);
            Assert.IsTrue(actual);
        }

        [TestMethod]
        public void Can_MoveUp_If_Not_Highest_One()
        {
            Subject.Handle(new ProfileItemAdded(new InterestParameter(DistributionType.FixedRate)));
            var fixedRate = new InterestParameter(DistributionType.FixedRate);
            Subject.Handle(new ProfileItemAdded(fixedRate));
            var actual = Subject.ItemCollection.CanMoveUp(fixedRate);
            Assert.IsTrue(actual);
        }

        [TestMethod]
        public void Edit_Test()
        {
            var rate = new InterestParameter();
            Subject.Edit(rate);
            Assert.IsNotNull(Subject.ItemDialog);
        }

        [TestMethod]
        public void Handle_Adds_The_Rate_To_List()
        {
            var fixedRate = new InterestParameter(DistributionType.FixedRate);

            Subject.Handle(new ProfileItemAdded(fixedRate));
            var actual = Subject.ItemCollection.Contains(fixedRate);
            Assert.IsTrue(actual);
        }

        [TestMethod]
        public void Handle_CancelEvent()
        {
            var dialog = new InterestParameterViewModel(null);
            Subject.Add();

            Subject.Handle(new CancelEvent(dialog));
            var actual = Subject.ItemDialog;
            Assert.IsNull(actual);
        }

        //[TestMethod()]
        //[DeploymentItem("NMortgage.UI.dll")]
        //public void RateDialogTest()
        //{
        //    var fixedRate = new InterestParameter(DistributionType.FixedRate);
        //    var dialog = new InterestParameterViewModel(null, fixedRate);
        //    PrivateObject param0 = new PrivateObject(dialog, new PrivateType(typeof(InterestParameterViewModel)));
        //    InterestParameterListViewModel_Accessor target = new InterestParameterListViewModel_Accessor(param0);
        //    InterestParameterViewModel expected = dialog;
        //    InterestParameterViewModel actual;
        //    target.RateDialog = expected;
        //    actual = target.RateDialog;
        //    Assert.AreEqual(expected, actual);
        //}
        [TestMethod]
        public void MoveDown()
        {
            var expected = 1;

            var fixedRate = new InterestParameter(DistributionType.FixedRate);
            Subject.Handle(new ProfileItemAdded(fixedRate));
            Subject.Handle(new ProfileItemAdded(new InterestParameter(DistributionType.FixedRate)));

            Subject.MoveDown(fixedRate);
            var actual = Subject.ItemCollection.IndexOf(fixedRate);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void MoveUp()
        {
            var expected = 0;

            Subject.Handle(new ProfileItemAdded(new InterestParameter(DistributionType.FixedRate)));
            var fixedRate = new InterestParameter(DistributionType.FixedRate);
            Subject.Handle(new ProfileItemAdded(fixedRate));
            Subject.MoveUp(fixedRate);
            var actual = Subject.ItemCollection.IndexOf(fixedRate);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void RateDialog_updates()
        {
            var fixedRate = new InterestParameter(DistributionType.FixedRate);
            var dialog = new InterestParameterViewModel(null, fixedRate);
            var actual = Subject.ItemDialog;
            Assert.IsNull(actual);

            Subject.Add();

            actual = Subject.ItemDialog;
            Assert.IsNotNull(actual);
        }

        [TestMethod]
        public void Remove()
        {
            var expected = 0;

            var fixedRate = new InterestParameter(DistributionType.FixedRate);
            Subject.Handle(new ProfileItemAdded(fixedRate));

            Subject.Remove(fixedRate);
            var actual = Subject.ItemCollection.Count;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void Title_Not_Null()
        {
            string actual = Subject.Title;
            Assert.IsNotNull(actual);
        }

        #endregion Methods
    }
}